import { OpMaterialIM, OpMaterialPM, OpMaterialPPM, OpMaterialLRM } from '@/model/operations/material.model';
import { defHttp } from '@/utils/http/axios';
import { formatToDateTime } from '@/utils/core/DateUtil';
import dayjs from 'dayjs';

const basicApi = '/operations/admin/material';

enum Api {
  LIST = basicApi + '/list',
  GET = basicApi + '/',
  ADD = basicApi,
  EDIT = basicApi,
  DEL_BATCH = basicApi + '/batch/',
  EXPORT = basicApi + '/export',
}

/** 查询资料管理列表 */
export const listOpMaterialApi = (params?: OpMaterialPPM) =>
  defHttp.get<OpMaterialLRM>({ url: Api.LIST, params });

/** 查询资料管理详细 */
export const getOpMaterialApi = (id: string) =>
  defHttp.get<OpMaterialIM>({ url: Api.GET, params: id });

/** 新增资料管理 */
export const addOpMaterialApi = (params: OpMaterialIM) =>
  defHttp.post({ url: Api.ADD, params });

/** 修改资料管理 */
export const editOpMaterialApi = (params: OpMaterialIM) =>
  defHttp.put({ url: Api.EDIT, params });

/** 删除资料管理 */
export const delOpMaterialApi = (ids: string | string[]) =>
  defHttp.delete({ url: Api.DEL_BATCH, params: ids.toString() });

/** 导出资料管理 */
export const exportOpMaterialApi = async (params?: OpMaterialPM) =>
  defHttp.export<any>(
    { url: Api.EXPORT, params: params },
    '资料管理_' + formatToDateTime(dayjs()) + '.xlsx',
  );
